using System;
using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;
using System.Collections;
using System.Text;
using System.Security.Cryptography;
namespace etbTOEIC
{
	/// <summary>
	/// Summary description for MyDatabase.
	/// </summary>
	public class MyDatabase : etbTOEIC.DataBase
	{
		public MyDatabase()
		{
			//
			// TODO: Add constructor logic here
			//
		}
		#region /* Lay thong tin Section, Topic, Question tu Database */
		public static Boolean GetSections(long SectionID, ref DataSet ds)
		{
			string strQuery = "SELECT * FROM tblSection";
			if (SectionID != 0)
				strQuery = strQuery + " WHERE SectionID=" + SectionID.ToString();
			return ExecuteQuery(strQuery, ref ds);
		}

		public static Boolean IsHasTopics(long SectionID)
		{
			int nCount = 0;
			string strQuery = "SELECT COUNT(*) FROM tblTopic";
			if (SectionID != 0)
				strQuery = strQuery + " WHERE SectionID=" + SectionID.ToString();
			ExecuteScalar(strQuery, ref nCount);
			return nCount > 0;
		}
		public static Boolean GetTopics(long SectionID, long TopicID, ref DataSet ds)
		{
			string strQuery = "SELECT T.*, S.Title As STitle ";
			strQuery += " FROM tblTopic T, tblSection S ";
			strQuery += " WHERE T.SectionID=S.SectionID ";
			if (SectionID != 0)
				strQuery += " AND T.SectionID=" + SectionID.ToString();
			if (TopicID != 0)
				strQuery += " AND T.TopicID=" + TopicID.ToString();
			strQuery += " ORDER BY S.SectionID, T.Title";
			
			return ExecuteQuery(strQuery, ref ds);
		}

		public static Boolean IsHasQuestions(long TopicID)
		{
			int nCount = 0;
			string strQuery = "SELECT COUNT(*) FROM tblQuestion";
			if (TopicID != 0)
				strQuery = strQuery + " WHERE TopicID =" + TopicID.ToString();
			ExecuteScalar(strQuery, ref nCount);
			return nCount > 0;
		}
		public static Boolean GetQuestions(long TopicID, long QuestionID, ref DataSet ds)
		{
			string strQuery = "SELECT Q.*, T.Title As TTitle, S.SectionID, S.Title As STitle ";
			strQuery += " FROM tblQuestion Q, tblTopic T, tblSection S ";
			strQuery += " WHERE T.SectionID=S.SectionID AND Q.TopicID=T.TopicID ";			
			if (TopicID != 0)
				strQuery += " AND T.TopicID=" + TopicID.ToString();
			if (QuestionID != 0)
				strQuery += " AND Q.QuestionID=" + QuestionID.ToString();
			strQuery += " ORDER BY S.SectionID, T.Title, Q.QuestionID";
			
			return ExecuteQuery(strQuery, ref ds);
		}
		public static Boolean GetCountQuestions(long SectionID, ref DataSet ds)
		{
			string strQuery = "SELECT S.SectionID, count(*) as QCount";
			strQuery += " FROM tblQuestion Q, tblTopic T, tblSection S ";
			strQuery += " WHERE T.SectionID=S.SectionID AND Q.TopicID=T.TopicID ";			
			if (SectionID != 0)
				strQuery += " AND S.SectionID=" + SectionID.ToString();
			strQuery += " GROUP BY S.SectionID";
			strQuery += " ORDER BY S.SectionID";
			
			return ExecuteQuery(strQuery, ref ds);
		}
		public static Boolean GetBookList(ref DataSet ds)
		{
			string strQuery = "SELECT * FROM tblBook";
			return ExecuteQuery(strQuery, ref ds);			
		}
		public static Boolean GetBooks(string BookID, ref DataSet ds)
		{
			string strQuery = "SELECT B.*";
			strQuery += " FROM tblBook B ";
			
			if (BookID != "")
				strQuery = strQuery + " WHERE B.BookID=\'" + BookID + "\'";

			return ExecuteQuery(strQuery, ref ds);
		}

		#endregion


		#region /* SQL lien quan den Exam */
		public static bool InsertTest(string ExamCode, DateTime DateCreate, string Class, string School, long TimeLast, string Notes, string Direction1A, string Direction1B, string Direction1C, string Direction1D, string Direction2A, string Direction2B, string Direction3, string TheEnd1A, string TheEnd1B, string TheEnd1C, string TheEnd1D, string TheEnd2A, string TheEnd2B, string TheEnd3)
		{
			string strQuery = "INSERT INTO tblTest(ExamCode, DateCreate, Class, School, TimeLast, Notes, Direction1A, Direction1B, Direction1C, Direction1D, Direction2A, Direction2B, Direction3, TheEnd1A, TheEnd1B, TheEnd1C, TheEnd1D, TheEnd2A, TheEnd2B, TheEnd3, LastUpdate)";
			strQuery += " VALUES('" + ExamCode + "', '" + DateCreate.ToString() + "', '" + Class + "', '" + School + "', " + TimeLast + ", '" +  Notes + "', '" + Direction1A + "', '" + Direction1B + "', '" + Direction1C + "', '" + Direction1D + "', '" + Direction2A + "', '" + Direction2B + "', '" + Direction3 + "', '" + TheEnd1A + "', '" + TheEnd1B + "', '" + TheEnd1C + "', '" + TheEnd1D + "', '" + TheEnd2A + "', '" + TheEnd2B + "', '" + TheEnd3 + "', '" + DateTime.Now.ToString() + "')";
			return ExecuteNonQuery(strQuery);
		}
		public static bool UpdateTest(long ExamID, string ExamCode, DateTime DateCreate, string Class, string School, long TimeLast, string Notes, string Direction1A, string Direction1B, string Direction1C, string Direction1D, string Direction2A, string Direction2B, string Direction3, string TheEnd1A, string TheEnd1B, string TheEnd1C, string TheEnd1D, string TheEnd2A, string TheEnd2B, string TheEnd3)
		{
			string strQuery = "UPDATE tblTest";
			strQuery += " SET ExamCode = '" + ExamCode + "', Class = '" + Class + "', School = '" + School + "', TimeLast = " + TimeLast + ", Notes = '" + Notes + "', Direction1A = '" + Direction1A + "', Direction1B = '" + Direction1B + "', Direction1C = '" + Direction1C + "', Direction1D = '" + Direction1D + "', Direction2A = '" + Direction2A + "', Direction2B = '" + Direction2B + "', Direction3 = '" + Direction3 + "', TheEnd1A = '" + TheEnd1A + "', TheEnd1B = '" + TheEnd1B + "', TheEnd1C = '" + TheEnd1C + "', TheEnd1D = '" + TheEnd1D + "', TheEnd2A = '" + TheEnd2A + "', TheEnd2B = '" + TheEnd2B + "', TheEnd3 = '" + TheEnd3 + "', LastUpdate = '" + DateTime.Now.ToString() + "'";
			strQuery += " WHERE ExamID = " + ExamID.ToString();
			return ExecuteNonQuery(strQuery);
		}
		public static bool DeleteTest(long ExamID)
		{
			string strQuery = "DELETE FROM tblDetailTest WHERE ExamID = " + ExamID.ToString();
			if(!ExecuteNonQuery(strQuery))
				return false;
			strQuery = "DELETE FROM tblTest WHERE ExamID = " + ExamID.ToString();
			return ExecuteNonQuery(strQuery);
			
		}
		public static bool ResetTempTest()
		{
			string strQuery = "DELETE FROM tblTempTest";
			return ExecuteNonQuery(strQuery);

		}
		public static bool TempToDetailTest()
		{
			int ExamID = 0;
			string strQuery = "SELECT MAX(ExamID) FROM tblTempTest";
			if(!ExecuteScalar(strQuery, ref ExamID) )
				return false;
			strQuery = "DELETE FROM tblDetailTest WHERE ExamID = " + ExamID.ToString();
			ExecuteNonQuery(strQuery);
			strQuery = "INSERT INTO tblDetailTest";
			strQuery += " SELECT *";
			strQuery += " FROM tblTempTest";
			return ExecuteNonQuery(strQuery);
		}
		public static bool UpdateTempTest()
		{
			int ExamID = 0;
			GenerateExamID(ref ExamID);
			string strQuery = "UPDATE tblTempTest";
			strQuery += " SET ExamID = " + ExamID.ToString();
			return ExecuteNonQuery(strQuery);
			
		}
		public static Boolean GenerateExamID(ref int nMax)
		{
			string strQuery = "SELECT MAX(ExamID)+ 1 FROM tblTest";
			return ExecuteScalar(strQuery, ref nMax);
			
		}
		public static bool InsertQuesToTest(long ExamID, long QuesID, long Order)
		{
			string strQuery = "INSERT INTO tblDetailTest(ExamID, QuestionID, QuesOrder)";
			strQuery += " VALUES(" + ExamID.ToString() + ", " + QuesID.ToString() + ", " + Order.ToString() + ")";
			return ExecuteNonQuery(strQuery);
		}
		public static bool InsertQuesToTmpTest(long ExamID, long QuesID, long Order)
		{
			string strQuery = "INSERT INTO tblTempTest(ExamID, QuestionID, QuesOrder)";
			strQuery += " VALUES(" + ExamID.ToString() + ", " + QuesID.ToString() + ", " + Order.ToString() + ")";
			return ExecuteNonQuery(strQuery);
		}
		public static bool CreateTempTesttbl(long ExamID)
		{
			ResetTempTest();
			string strQuery = "INSERT INTO tblTempTest";
			strQuery += " SELECT *";
			strQuery += " FROM tblDetailTest";
			strQuery += " WHERE ExamID = " + ExamID.ToString();
			return ExecuteNonQuery(strQuery);
		}
		public static bool GetTests(ref DataSet ds)
		{
			string strQuery = "SELECT ExamID, ExamCode, DateCreate, Class, School, TimeLast, Notes";
			strQuery +=	" FROM tblTest";
			strQuery +=	" GROUP BY DateCreate, ExamCode, ExamID, Class, School, TimeLast, Notes";
			strQuery += " ORDER BY DateCreate, ExamCode";
						
			return ExecuteQuery(strQuery, ref ds);			
		}
		public static bool GetTempTopicDetails(long SectionID, long TopicID, ref DataSet ds)
		{
			string strQuery = "SELECT S.SectionID, S.Title As STitle, T.TopicID, T.Title As TTitle, T.ImageFile, T.Passages, TT.QuesOrder" ;
			strQuery += " FROM tblSection S, tblTopic T, tblQuestion Q, tblTempTest TT";
			strQuery += " WHERE TT.QuestionID = Q.QuestionID AND Q.TopicID = T.TopicID AND T.SectionID = S.SectionID";
			if (SectionID>0) strQuery += " AND S.SectionID = "+SectionID.ToString();
			if (TopicID>0) strQuery += " AND T.TopicID = "+TopicID.ToString();
			strQuery += " ORDER BY S.SectionID, TT.QuesOrder ASC";
			
			return ExecuteQuery(strQuery, ref ds);			
		}
		public static bool GetTempTestDetails(long SectionID, long TopicID, ref DataSet ds)
		{
			string strQuery = "SELECT S.SectionID, S.Title As STitle, T.Title As TTitle, T.Passages As TPassages, T.TopicID, Q.QuestionID, Q.QuestionText, Q.ImageFile, Q.Tape, Q.ChoiceA, Q.ChoiceB, Q.ChoiceC, Q.ChoiceD, Q.Answer, TT.QuesOrder" ;
			strQuery += " FROM tblSection S, tblTopic T, tblQuestion Q, tblTempTest TT";
			strQuery += " WHERE TT.QuestionID = Q.QuestionID AND Q.TopicID = T.TopicID AND T.SectionID = S.SectionID";
			if (SectionID>0) strQuery += " AND S.SectionID = "+SectionID.ToString();
			if (TopicID>0) strQuery += " AND T.TopicID = "+TopicID.ToString();
			strQuery += " ORDER BY S.SectionID, TT.QuesOrder ASC";
			
			return ExecuteQuery(strQuery, ref ds);			
		}
		#endregion
		
		#region  /* Xu ly voi Crystal Report  */
		public static Boolean GetData4Part1(ref DataSet ds)
		{
			string strSql = "Select S.Title, S.Direction, Q.ImageFile, P.QuesOrder";
			strSql+= " from tblQuestion Q, tblSection S, tblTopic T, tblTempTest P";
			strSql+= " where S.SectionID=1 and S.SectionID=T.SectionID and Q.TopicID=T.TopicID and Q.QuestionID = P.QuestionID";	
			strSql+= " order by P.QuesOrder,S.Title, S.Direction, Q.ImageFile";	
			return DataBase.ExecuteQuery(strSql, ref ds);
		}
		public static Boolean GetData4Part2(ref DataSet ds)
		{
			string strSql = "Select Title, Direction, QuesOrder";
			strSql+= " from tblSection, tblTempTest, tblQuestion";
			strSql+= " where SectionID=2 and tblTempTest.QuestionID = tblQuestion.QuestionID";
			return DataBase.ExecuteQuery(strSql, ref ds);
		}
		public static Boolean GetData4Part3(ref DataSet ds)
		{
			string strSql = "Select S.Title, S.Direction, Q.QuestionText, Q.ChoiceA, Q.ChoiceB, Q.ChoiceC, Q.ChoiceD, Q.QuestionID";
			strSql+= " from tblQuestion Q, tblSection S, tblTopic T";
			strSql+= " where S.SectionID=T.SectionID and Q.TopicID=T.TopicID and S.SectionID=3 and Q.QuestionID between 51 and 80";
			return DataBase.ExecuteQuery(strSql, ref ds);
		}
		public static Boolean GetData4Part4(ref DataSet ds)
		{
			string strSql = "Select S.Title, S.Direction, Q.QuestionText, Q.ChoiceA, Q.ChoiceB, Q.ChoiceC, Q.ChoiceD, Q.QuestionID";
			strSql+= " from tblQuestion Q, tblSection S, tblTopic T";
			strSql+= " where S.SectionID=T.SectionID and Q.TopicID=T.TopicID and S.SectionID=4 and Q.QuestionID between 81 and 100";
			return DataBase.ExecuteQuery(strSql, ref ds);
		}
		public static Boolean GetData4Part5(ref DataSet ds)
		{
			string strSql = "Select S.Title, S.Direction, Q.QuestionText, Q.ChoiceA, Q.ChoiceB, Q.ChoiceC, Q.ChoiceD, Q.QuestionID";
			strSql+= " from tblQuestion Q, tblSection S, tblTopic T";
			strSql+= " where S.SectionID=T.SectionID and Q.TopicID=T.TopicID and S.SectionID=5 and Q.QuestionID between 101 and 140";
			return DataBase.ExecuteQuery(strSql, ref ds);
		}
		public static Boolean GetData4Part6(ref DataSet ds)
		{
			string strSql = "Select S.Title, S.Direction, Q.QuestionText, P.QuesOrder";
			strSql+= " from tblQuestion Q, tblSection S, tblTopic T, tblTempTest P";
			strSql+= " where S.SectionID=T.SectionID and Q.TopicID=T.TopicID and S.SectionID=6 and Q.QuestionID = P.QuestionID";
			return DataBase.ExecuteQuery(strSql, ref ds);
		}
		public static Boolean GetData4Part7(ref DataSet ds)
		{
			string strSql = "Select S.Title, S.Direction, Q.QuestionText, Q.ChoiceA, Q.ChoiceB, Q.ChoiceC, Q.ChoiceD, P.QuesOrder, T.ImageFile, Q.TopicID";
			strSql+= " from tblQuestion Q, tblSection S, tblTopic T, tblTempTest P";
			strSql+= " where S.SectionID=T.SectionID and Q.TopicID=T.TopicID and S.SectionID=7 and Q.QuestionID = P.QuestionID";
			strSql+= " group by Q.TopicID,S.Title, S.Direction, Q.QuestionText, Q.ChoiceA, Q.ChoiceB, Q.ChoiceC, Q.ChoiceD, P.QuesOrder, T.ImageFile";
			strSql+= " order by P.QuesOrder";
			return DataBase.ExecuteQuery(strSql, ref ds);
		}
		#endregion
		public static Boolean GenerateTopicID(ref int nMax)
		{
			string strQuery = "SELECT MAX(TopicID)+ 1 FROM tblTopic";
			return ExecuteScalar(strQuery, ref nMax);
			
		}
		public static Boolean GenerateQuesID(ref int nMax)
		{
			string strQuery = "SELECT MAX(QuestionID)+ 1 FROM tblQuestion";
			return ExecuteScalar(strQuery, ref nMax);
			
		}	
		public static void GetLinkIDRow(string sId, ref long SID, ref long TID, ref long QID)
		{
			SID = TID = QID = 0;
			DataSet myDataSet = new DataSet();

			long ID = Convert.ToInt64(sId.Substring(1));
			if (sId.StartsWith("S"))
				MyDatabase.GetSections(ID, ref myDataSet);
			else if (sId.StartsWith("T"))
				MyDatabase.GetTopics(0, ID, ref myDataSet);
			else
				MyDatabase.GetQuestions(0, ID, ref myDataSet);
			
			foreach(DataTable myTable in myDataSet.Tables)
			{
				foreach(DataRow myRow in myTable.Rows)
				{
					SID = myTable.Columns.Contains("SectionID")? Convert.ToInt64(myRow["SectionID"].ToString()) : 0;
					TID = myTable.Columns.Contains("TopicID")?	 Convert.ToInt64(myRow["TopicID"].ToString()) : 0;
					QID = myTable.Columns.Contains("QuestionID")? Convert.ToInt64(myRow["QuestionID"].ToString()) : 0;
					break;
				}
			}
		}
		
		#region /* Xu ly voi TempTest */
		public static bool InsertTempTest(long QuesID, long Order)
		{
			string strQuery = "INSERT INTO tblTempTest(ExamID, QuestionID, QuesOrder)";
			strQuery += " VALUES(1, " + QuesID.ToString() + ", " + Order.ToString() + ")";
			return ExecuteNonQuery(strQuery);
		}

		public static bool ExecuteGenQuery(string strQuery, ref DataSet ds)
		{
			return ExecuteQuery(strQuery, ref ds);
		}
		#endregion

		public static string GetSound(long TopicID, long QuestionID)
		{
			string s = "";
			string stQuery = "";
			if(TopicID > 0)
				stQuery = "SELECT SoundFile FROM tblTopic WHERE TopicID = " + TopicID.ToString();
			else if(QuestionID > 0)
				stQuery = "SELECT SoundFile FROM tblQuestion WHERE QuestionID = " + QuestionID.ToString();
			Object[] obj = new Object[1];
			ExecuteQuery(stQuery,ref obj);
			if(obj[0] != null)
				s = obj[0].ToString();
			return s;
		}
		public static ArrayList GetSections(long ExamID)
		{
			ArrayList arr = new ArrayList();
			DataSet ds = new DataSet();
			string	stQuery = "SELECT DISTINCT tblTopic.SectionID";
			stQuery = stQuery + " FROM tblDetailTest, tblQuestion, tblTopic ";
			stQuery = stQuery + " WHERE tblDetailTest.QuestionID=tblQuestion.QuestionID AND tblQuestion.TopicID=tblTopic.TopicID";
			stQuery = stQuery + " AND tblDetailTest.ExamID = " + ExamID.ToString();
			ExecuteQuery(stQuery, ref ds);
			foreach(DataTable dtb in ds.Tables)
				foreach(DataRow dr in dtb.Rows)
					arr.Add(dr.ItemArray[0]);
			return arr;
		}
		#region /* Xu ly dang nhap, doi mat khau */
		static public bool isValidUser(string username,string password)
		{
			string  strsql = "SELECT COUNT(*) FROM tblUser";
			strsql += " WHERE UserName='" + username + "' AND Pass='" + password + "'";
			int nCount = 0;
			ExecuteScalar(strsql,ref nCount);
			return nCount > 0;
			
		}
		public static Byte[] EncodePass(string pass)
		{
			MD5CryptoServiceProvider md5Hasher =  new MD5CryptoServiceProvider();
			Byte[] hashedBytes;   
			UTF8Encoding encoder = new UTF8Encoding();
			hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(pass));      
			return hashedBytes;

		}
		static public bool UpdatePass(string username, string password)
		{
			string strsql = "UPDATE tblUser SET Pass='" + password + "' WHERE UserName = '" + username + "'";
			return ExecuteNonQuery(strsql);
		}
		#endregion

		#region /* Lay Thong tin ve Test */
		public static Boolean GetExamInfo(long nExamID,ref DateTime dtCreate,ref DateTime dtLastUpdate, ref int[] arrCount, ref string stExamCode)
		{
			DataSet ds = new DataSet();

			string stQuery = "SELECT T.SectionID, Count(D.QuestionID) AS nCount";
			stQuery += " FROM tblDetailTest D, tblTopic T, tblQuestion Q";
			stQuery += " WHERE ExamID =" + nExamID.ToString() + " AND D.QuestionID = Q.QuestionID AND Q.TopicID = T.TopicID";
			stQuery += " GROUP BY T.SectionID";
			stQuery += " ORDER BY T.SectionID";

			if(!ExecuteQuery(stQuery, ref ds))
				return false;
			foreach(DataRow row in ds.Tables[0].Rows)
			{
				int index = Convert.ToInt32(row["SectionID"].ToString());
				arrCount[index - 1] = (int)row["nCount"];
			}
			stQuery = "SELECT ExamCode, DateCreate, LastUpdate FROM tblTest WHERE ExamID=" + nExamID.ToString();
			ds = new DataSet();
			if(!ExecuteQuery(stQuery, ref ds))
				return false;
			
			DataRow dtr = ds.Tables[0].Rows[0];
			if(dtr.ItemArray[0] != null)
				stExamCode = dtr.ItemArray[0].ToString();
			if(dtr.ItemArray[1] != null)
				dtCreate = (DateTime)dtr.ItemArray[1];
			if(dtr.ItemArray[2] != null)
				dtLastUpdate = (DateTime)dtr.ItemArray[2];
			return true;

		}
		public static Boolean GetExamInfo(long nExamID,ref DateTime dtCreate,ref DateTime dtLastUpdate, ref string stSchool, ref string stClass, ref long Duration)
		{
			DataSet ds = new DataSet();

			string stQuery = "SELECT DateCreate, LastUpdate, School, Class, TimeLast FROM tblTest WHERE ExamID=" + nExamID.ToString();
			if(!ExecuteQuery(stQuery, ref ds))
				return false;
			
			foreach(DataRow row in ds.Tables[0].Rows)
			{
				if(row.ItemArray[0] != null)
					dtCreate = (DateTime)row.ItemArray[0];
				if(row.ItemArray[1] != null)
					dtLastUpdate = (DateTime)row.ItemArray[1];
				if(row.ItemArray[2] != null)
					stSchool = row.ItemArray[2].ToString();
				if(row.ItemArray[3] != null)
					stClass = row.ItemArray[3].ToString();
				if(row.ItemArray[4] != null)
					Duration = Convert.ToInt64(row.ItemArray[4].ToString());
			}
			return true;

		}
		#endregion

		#region /* Xu ly thong tin ve sach : Insert, Update, Delete */
		public static Boolean InsertBook(string stBookCode, string stBookName, string stWriter)
		{
			string stQuery = "INSERT INTO tblBook(BookCode, BookName, Writer)";
			stQuery += " VALUES('" + stBookCode + "','" + stBookName +  "','" + stWriter + "')";
			return ExecuteNonQuery(stQuery);
		}
		public static Boolean UpdateBook(int BookID, string stBookCode, string stBookName, string stWriter)
		{
			string stQuery = "UPDATE tblBook SET BookCode='" + stBookCode + "',BookName = '" + stBookName + "',Writer='" + stWriter + "' WHERE BookID=" + BookID.ToString();
			return ExecuteNonQuery(stQuery);
		}
		public static Boolean DeleteBook(int BookID)
		{
			string stQuery = "DELETE FROM tblBook WHERE BookID=" + BookID.ToString();
			return ExecuteNonQuery(stQuery);
		}
		public static Boolean LoadBook(int BookID, ref string stBookCode, ref string stBookName, ref string stWriter)
		{
			DataSet ds = new DataSet();
			string stQuery = "SELECT BookCode,BookName,Writer FROM tblBook WHERE BookID=" + BookID.ToString();
			if(!ExecuteQuery(stQuery, ref ds))
				return false;
			foreach(DataRow row in ds.Tables[0].Rows)
			{
				stBookCode = row.ItemArray[0].ToString();
				stBookName = row.ItemArray[1].ToString();
				stWriter = row.ItemArray[2].ToString();
			}
			return true;
		}
		public static Boolean LoadBooks(ref DataSet ds)
		{	
			string stQuery = "SELECT BookID, BookName FROM tblBook";
			return ExecuteQuery(stQuery, ref ds);
		}

		#endregion

		#region /* Xu ly cap nhat thong tin Section */
		public static Boolean LoadSection(int SectionID, ref string stTittle, ref string stDirection, ref string stTheEnd)
		{
			string stQuery = "SELECT Title, Direction, TheEnd FROM tblSection WHERE SectionID = " + SectionID.ToString();
			DataSet ds = new DataSet();
			if(!MyDatabase.ExecuteQuery(stQuery, ref ds))
				return false;
			stTittle = ds.Tables[0].Rows[0].ItemArray[0].ToString();
			stDirection = ds.Tables[0].Rows[0].ItemArray[1].ToString();
			stTheEnd = ds.Tables[0].Rows[0].ItemArray[2].ToString();
			return true;
		}
		public static Boolean UpdateSection(int SectionID, string stTitle, string stDirection, string stTheEnd)
		{
			string stQuery = "UPDATE tblSection SET Title='" + stTitle + "',Direction = '" + stDirection + "',TheEnd='" + stTheEnd + "' WHERE SectionID=" + SectionID.ToString();
			return ExecuteNonQuery(stQuery);
		}
		public static Boolean LoadSections(ref DataSet ds)
		{	
			string stQuery = "SELECT SectionID, Title FROM tblSection";
			return ExecuteQuery(stQuery, ref ds);
		}

		#endregion
		
		
	}
	
}
